package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.SysTaocanOrder;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysTaocanOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.List;

/**
 * 套餐计费订单Controller
 *
 * @author zjw
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/system/taocanOrder")
public class SysTaocanOrderController extends BaseController {
    @Autowired
    private ISysTaocanOrderService sysTaocanOrderService;

    /**
     * 查询套餐计费订单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTaocanOrder sysTaocanOrder) {
        startPage();
        List<SysTaocanOrder> list = sysTaocanOrderService.selectSysTaocanOrderList(sysTaocanOrder);
        return getDataTable(list);
    }

    /**
     * 导出套餐计费订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "套餐计费订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTaocanOrder sysTaocanOrder) {
        List<SysTaocanOrder> list = sysTaocanOrderService.selectSysTaocanOrderList(sysTaocanOrder);
        ExcelUtil<SysTaocanOrder> util = new ExcelUtil<SysTaocanOrder>(SysTaocanOrder.class);
        util.exportExcel(response, list, "套餐计费订单数据");
    }

    /**
     * 获取套餐计费订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        return success(sysTaocanOrderService.selectSysTaocanOrderByOrderId(orderId));
    }

    /**
     * 新增套餐计费订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "套餐计费订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTaocanOrder sysTaocanOrder) {
        return toAjax(sysTaocanOrderService.insertSysTaocanOrder(sysTaocanOrder));
    }

    /**
     * 修改套餐计费订单
     */
//    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "套餐计费订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTaocanOrder sysTaocanOrder) {
        return toAjax(sysTaocanOrderService.updateSysTaocanOrder(sysTaocanOrder));
    }

    /**
     * 删除套餐计费订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "套餐计费订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds) {
        return toAjax(sysTaocanOrderService.deleteSysTaocanOrderByOrderIds(orderIds));
    }
}
